package com.ruoyi.web.pojo.request.insect;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.net.url.UrlBuilder;
import com.google.common.collect.Lists;
import com.ruoyi.common.utils.CommonUtils;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class InsectSumDataRequest {


    @ApiModelProperty(value = "设备ID")
    @NotEmpty(message = "设备id不能为空")
    private String deviceId;

    @ApiModelProperty(value = "数据开始时间,格式 yyyy-MM-dd")
    private String startTime;

    @ApiModelProperty(value = "数据结束时间")
    private String endTime;

    @ApiModelProperty(value = "日期类型，1 全部，2 按年 , 3 按月 , 4 本季度")
    private Integer dateType = 1;

    @ApiModelProperty(value = "时间 年格式 yyyy , 月格式 yyyy-MM")
    private String time;

    @ApiModelProperty(value = "设备ID集合")
    private List<String> deviceIds;

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
        this.deviceIds = CollUtil.newArrayList(deviceId);
    }

    public void buildDefTime(String endTime) {
        this.setEndTime(endTime);
        this.startTime = CommonUtils.computeTime(endTime,-15);
    }

    public UrlBuilder getQuery(){
        UrlBuilder builder = UrlBuilder.of();
        if (CollUtil.isNotEmpty(deviceIds)){
            builder.addQuery("deviceId",this.getDeviceIds().stream().collect(Collectors.joining(",")));
        }
        if (this.getTime() != null)builder.addQuery("time",this.getTime());
        if (this.getStartTime() != null) builder.addQuery("startTime",this.getStartTime());
        if (this.getEndTime() != null) builder.addQuery("endTime",this.getEndTime());
        builder.addQuery("dateType",this.getDateType());

        return builder;
    }

}
